﻿
	function setGridItemsEqualHeight($)
	{
		var SPACING = 20;
		if ($(window).width() >= 480)
		{
			$('.category-products-grid').removeClass("auto-height");
			
			var gridItemMaxHeight = 0;
			$('.category-products-grid > .item').each(function() {
				$(this).css("height", "auto");
				
				////////////////////////////////////////////////////////////////
									var actionsHeight = $(this).find('.actions').height();
					$(this).css("padding-bottom", (actionsHeight + SPACING) + "px"); //Set new padding
								////////////////////////////////////////////////////////////////
				
				gridItemMaxHeight = Math.max(gridItemMaxHeight, $(this).height());
			});
			
			//Apply max height
			$('.category-products-grid > .item').css("height", gridItemMaxHeight + "px");
		}
		else
		{
			$('.category-products-grid').addClass("auto-height");
			$('.category-products-grid > .item').css("height", "auto");
			$('.category-products-grid > .item').css("padding-bottom", "20px");
		}
	}
		
	function activateMobileMenu($)
	{
		if ($(window).width() < 960)
		{
			$('#mobnav').show();
			$('.vertnav-top').addClass('mobile');
			$('#nav').addClass('mobile');
		}
		else
		{
			$('#nav').removeClass('mobile');
			$('.vertnav-top').removeClass('mobile');
			$('#mobnav').hide();
		}
	}



	jQuery(function ($) {

	    activateMobileMenu(jQuery);

	    $('#mobnav-trigger').toggle(function () {
	        $(this).addClass('active');
	        $('.vertnav-top').addClass('show');
	    }, function () {
	        $(this).removeClass('active');
	        $('.vertnav-top').removeClass('show');
	    });

	    $("#nav > li").hover(function () {
	        //$(this).find(".level0").stop(true, true).delay(150).fadeIn(300);
	        $(this).find(".level0").stop(true, true).delay(150).fadeIn(300, "easeOutCubic");
	    }, function () {
	        //$(this).find(".level0").stop(true, true).delay(150).fadeOut(300);
	        $(this).find(".level0").stop(true, true).delay(150).fadeOut(300, "easeInCubic");
	    });

//	    var eli = $("#cart-sidebar").text();
//	    if ($.trim(eli).length != 0) {
//	        $("#block_style").html("<style type='text/css'> #mini-cart:hover .block-content { display:block; position:fixed; left:25%; top:25%; z-index:10000; } </style>");
//	        $("#mini-cart").hover(function () {
//	            $(this).addClass('hover');
//	            //$("#mini-cart .block-content").stop(true, true).delay(300).fadeIn(500);
//	            $("#mini-cart .block-content").stop(true, true).delay(600).fadeIn(500, "easeOutCubic");
//	        }, function () {
//	            //$("#mini-cart .block-content").stop(true, true).delay(300).fadeOut(500);
//	            $("#mini-cart .block-content").stop(true, true).delay(300).fadeOut(500, "easeInCubic");
//	        });
//	    }



	    $(".dropdown-button").mouseenter(function () {
	        $(this).click();
	    });
	    $(".dropdown-button").click(function () {
	        $(this).addClass('hover');
	        var el = $(this).find("ul");
	        if ($(window).width() >= 480)
	            //el.stop(true, true).delay(300).fadeIn(500);
                el.stop(true, true).delay(300).fadeIn(500, "easeOutCubic");
	        else
	            el.show();

	        //Positionning
	        var x = el.offset().left;
	        if (x < 0) {
	            var space = $(this).offset().left;
	            el.css("left", (-1) * space);
	            el.css("right", "auto");
	        }
	    }).mouseleave(function () {
	        var el = $(this).find("ul");
	        if ($(window).width() >= 480)
                //el.stop(true, true).delay(300).fadeOut(500);
	            el.stop(true, true).delay(300).fadeOut(500, "easeInCubic");
	        else
	            el.hide();
	        el.css("left", "");
	        el.css("right", "");
	    });

	    $(window).scroll(function () {
	        if ($(this).scrollTop() > 100) {
	            $('#scroll-to-top').fadeIn();
	        }
	        else {
	            $('#scroll-to-top').fadeOut();
	        }
	    });
	    $('#scroll-to-top').click(function () {
	        //$("html, body").animate({ scrollTop: 0 }, 600);
	        $("html, body").animate({ scrollTop: 0 }, 600, "easeOutCubic");
	        return false;
	    });



	    $('.category-products-grid > .item').hover(function () {
	        //$(this).find(".display-onhover").fadeIn(400);
	        $(this).find(".display-onhover").fadeIn(400, "easeInCubic");
	    }, function () {
	        $(this).find(".display-onhover").hide();
	    });



	    /* On resize */
	    var t;
	    $(window).resize(function () {
	        clearTimeout(t);
	        t = setTimeout(function () {

	            setGridItemsEqualHeight($);

	            $('.itemslider').each(function (index) {
	                var s = $(this).data('flexslider');
	                if (s != null) s.flexAnimate(0);
	            });

	            activateMobileMenu($);

	        }, 100);
	    });

	});          /* end: jQuery(){...} */
	
	
	
	jQuery(window).load(function(){
		
			setGridItemsEqualHeight(jQuery);
		
	}); /* end: jQuery(window).load(){...} */
